package com.yutel.http.HttpServer.handler;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

import com.dd.plist.NSObject;
import com.dd.plist.PropertyListParser;
import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;

public class PlayHandler implements HttpHandler {

	@Override
	public void handle(HttpExchange he) throws IOException {
		System.out.println("PlayHandler()");
		Headers headers = he.getRequestHeaders();
		for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
			System.out.println("req:key=" + entry.getKey() + ",value="
					+ entry.getValue());
		}
		he.sendResponseHeaders(200, 0);
		Headers responseHeaders = he.getResponseHeaders();
		for (Map.Entry<String, List<String>> entry : responseHeaders.entrySet()) {
			System.out.println("res:key=" + entry.getKey() + ",value="
					+ entry.getValue());
		}
		InputStream is = he.getRequestBody();
		try {
			NSObject plist = PropertyListParser.parse(is);
			System.out.println(plist.toXMLPropertyList());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
